﻿using System;
using System.Collections.Generic;
using System.Globalization;

namespace HappyBa.Core.Data
{
    public class Base
    {
        public int Id { get; set; }
        public override string ToString()
        {
            return Id.ToString(CultureInfo.InvariantCulture);
        }
    }

    public class NamedBase : Base
    {
        public string Name { get; set; }
        public override string ToString()
        {
            return Name;
        }
    }

    public class CustomField : Base
    {
        public string Name { get; set; }
        public string Value { get; set; }
    }

    public class EntityBase : NamedBase
    {
        public string Description { get; set; }
        public DateTime? StartDate { get; set; }
        public DateTime? EndDate { get; set; }
        public DateTime? ModifyDate { get; set; }
        public DateTime? LastCommentDate { get; set; }
        public Base EntityType { get; set; }
        public User Owner { get; set; }
        public IList<CustomField> CustomFields {get; set;}
        public override string ToString()
        {
            return Id + ": " + Name;
        }

        public EntityBase()
        {
            CustomFields = new List<CustomField>();
        }
    }

    public class StatebleEntityBase : EntityBase
    {
        public EntityState EntityState { get; set; }
    }

    public class EstimatableEntityBase : StatebleEntityBase
    {
        public decimal Effort { get; set; }
        public decimal EffortCompleted { get; set; }
        public decimal EffortToDo { get; set; }
        public decimal TimeSpent { get; set; }
        public decimal TimeRemain { get; set; }
        public DateTime? PlannedStartDate { get; set; }
        public DateTime? PlannedEndDate { get; set; }
        public Priority Priority { get; set; }
        public Base UserStory { get; set; }
        public Base Feature { get; set; }
        public Base Iteration { get; set; }
        public Base Release { get; set; }
        public Base Project { get; set; }
    }

    public class Priority : NamedBase { }
    public class EntityState : NamedBase { }
    public class EntityType : NamedBase { }
    public class Role : NamedBase { }

    public class Assignment : Base
    {
        public Base Assignable { get; set; }
        public Base Role { get; set; }
        public User GeneralUser { get; set; }
    }

    public class Time : Base
    {
        public EntityBase Assignable { get; set; }
        public User User { get; set; }
        public DateTime Date { get; set; }
        public decimal Spent { get; set; }
    }

    public class User : Base
    {
        public string Kind { get; set; }
        public string Email { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public override string ToString()
        {
            return FirstName + " " + LastName;
        }
    }

    public class Comment : Base
    {
        public string Description { get; set; }
        public Base General { get; set; }
        public User Owner { get; set; }
        public DateTime CreateDate { get; set; }
    }

    public class Impediment : StatebleEntityBase
    {
        public Base Project { get; set; }
        public Base Assignable { get; set; }
    }

    public class Project : EntityBase
    {
        public ProjectType Type { get; set; }
    }
    public class UserStory : EstimatableEntityBase{}
    public class Bug : EstimatableEntityBase{}
    public class Task : EstimatableEntityBase{}

    public class BaseCollection<T>
        where T : Base
    {
        public IList<T> Items { get; set; }
    }
}
